#!/usr/bin/perl -w

open (IN, $ARGV[0]) or die $!;

while($in = <IN>){
    chomp $in;
    if ($in =~ /author_list>(.*)<\/author/){
            push @array, $1;
        }
    elsif ($in =~ /title>(.*)<\/title/){
            push @array, $1;
      
        }
    elsif ($in =~ /PUBMED" dbkey=\"(\d+)\"/){
            push @array, $1;

        }
    elsif ($in =~ /journal>(.*)<\/journal/){
            push @array, $1;
        }        
    elsif ($in =~ /firstpage=/){
            if ($in =~ /firstpage=\"(\d+)\".*lastpage=\"(\d+)\".*volume=\"(\d+)\".*issue=\"(\d+)\"/){
                push @array, $1;
                push @array, $2;
                push @array, $3;
                push @array, $4;
            }
            elsif ($in =~ /firstpage=\"(\d+)\".*lastpage=\"(\d+)\".*volume=\"(\d+)\"\s\/\>/){
                push @array, $1;
                push @array, $2;
                push @array, $3;
            }
        }
    elsif ($in =~ /year>(\d+)<\/year/){
            push @array, $1;
        }        
    elsif (scalar(@array) >= 8){
            if (scalar(@array) == 8){
                print "$array[0] \\n$array[1] \\n$array[3] $array[7]. $array[6]:$array[4]-$array[5]. \\nPMID: $array[2].\\n\\n";
                undef @array;
                }
            elsif (scalar(@array) == 9){
                print "$array[0] \\n$array[1] \\n$array[3] $array[8]. $array[6]($array[7]):$array[4]-$array[5]. \\nPMID: $array[2].\\n\\n";
                undef @array;
            }
        }
    }
